package com.polytech.ihm;

import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;

import javax.imageio.ImageIO;
import javax.swing.JFrame;
import javax.swing.JPanel;

public class PanelPicture extends JPanel  {
	private int width, hight;
	private String picture;
	private int mode;
	public  static final int NOSIZE=1;
	public  static final int REPEAT=2;
	public  static final int DEFINESIZE=3;
	private JFrame showCar;



	public PanelPicture(int mode) {
		this.mode=mode;
	}


	public PanelPicture(int width, int hight,int mode) {
		this.width = width;
		this.hight = hight;
		this.mode=mode;
		this.setPreferredSize(new Dimension(width, hight));
	}


	public int getWidth() {
		return width;
	}
	public void setWidth(int width) {
		this.width = width;
	}
	public int getHight() {
		return hight;
	}
	public void setHight(int hight) {
		this.hight = hight;
	}
	public String getPicture() {
		return picture;
	}
	public void setPicture(String picture) {
		this.picture = picture;
	}

	@Override
	protected void paintComponent(Graphics g) {
		super.paintComponent(g);
		BufferedImage im;


		try {
			im = ImageIO.read(new File(picture));
			if(mode==DEFINESIZE)
			g.drawImage(im, 0, 0, width, hight, null);
			
			if(mode==NOSIZE)
				g.drawImage(im, 0, 0, im.getWidth(), im.getHeight(), null);

		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

	}


	public void show() {
		showCar=new JFrame("The Car");
		PanelPicture p=new PanelPicture(500, 500, PanelPicture.DEFINESIZE);
		p.setPicture(picture);
		showCar.add(p);
		showCar.pack();
		showCar.setVisible(true);
		showCar.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);



	}


	public void hide() {
		showCar.dispose();
		showCar=null;

	}


}
